<?php
namespace app\admin\logic;

//属性页
use think\facade\Request;

class GoodsPropLogic{
    //prop 分属性值
    public static function propValues($prop){
//        $p=[];
//        foreach ($prop as &$v){
//            $p[]=Db::table('ecm_goods_prop_value')->where('pid','=',$v['pid'])->column('prop_value');
//        foreach ($p as $s){
//            $pv=implode(",",$s);
//        }
//            $v['pvalues']=$pv;
//        }

        foreach ($prop as &$v){
            //转数组
            $v['pvalues']=explode(",",$v['pvalues']);
            $pvalues=[];
            foreach ($v['pvalues'] as $s){
                $pvalues[]=\app\admin\model\GoodsProp::propOne($s);
            }
            //转字符串
            $pvalues=implode(",",$pvalues);
            $v['pvalues']=$pvalues;
        }
        return $prop;
    }
    //prop 留值
    public static function  propData(){
        $param=Request::param();
        $data=[
            'keywords'=>isset($param['keywords'])?$param['keywords']:'',
            'pvalue'=>isset($param['pvalue'])?$param['pvalue']:[],
        ];
        return $data;

    }
    //  prop where语句
    public static function  propWhere(){
        $param=Request::param();
        $where=[];
        $whereOr=[];
        if (isset($param['keywords']) && !empty($param['keywords'])){
            $where[]=['pname','like','%'.$param['keywords'].'%'];
        }
        if (isset($param['pvalue'])){
            foreach ($param['pvalue'] as $v){
                $whereOr[]=['pvalues','find in set',$v];
            }

        }
        return [$where,$whereOr];

    }



}